package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         80,
		Discription: "删除有序数组中的重复项",
		Level:       2,
		Labels: map[string]int{
			"快慢指针":  1,
			"双指针滑动": 1,
		},
	})
}

func RemoveDuplicates2(nums []int) int {
	if len(nums) <= 2 {
		return len(nums)
	}

	slow := 2
	fast := 2
	for fast < len(nums) {
		//重复元素不超过2个
		if nums[fast] != nums[slow-2] {
			nums[slow] = nums[fast]
			slow++
		}
		fast++
	}

	//到最后[:slow]是删除后的数组
	return slow
}
